$tree = array();
$tree[1] = array('id' => 1, 'name' => 'Položka 1', 'parent' => 0);
$tree[2] = array('id' => 2, 'name' => 'Položka 1.1', 'parent' => 1);
$tree[3] = array('id' => 3, 'name' => 'Položka 1.2', 'parent' => 1);
$tree[4] = array('id' => 4, 'name' => 'Položka 1.1.1', 'parent' => 2);
$tree[5] = array('id' => 5, 'name' => 'Položka 1.1.1.1', 'parent' => 4);
$tree[6] = array('id' => 6, 'name' => 'Položka 2', 'parent' => 0);
$tree[843] = array('id' => 843, 'name' => 'Položka 2.1', 'parent' => 6);
$tree[1000] = array('id' => 1000, 'name' => 'Položka 2.1.1', 'parent' => 843);
$items = array();
foreach ($tree as $row)
{
$items[$row['id']]= $row['parent'];
}
//print_R($items);
function createParents($id)
{
global $items;
$return[] = $id;
while ($items[$id])
{
$id = $items[$id];
$return[] = $id;
}
return $return;
}
$parents = array();
if ($_GET['id'])
{
$parents = createParents($_GET['id']);
$crumbs = array_reverse($parents);
// crumbs
$pipe = FALSE;
foreach ($crumbs as $par)
{
if ($pipe)
echo " | ";
echo "".$tree[$par]['name']."";
if (!$pipe)
{
$pipe = TRUE;
}
}
}
tree(0, 0, $tree);
//tree(0, 0, $tree, TRUE);
function tree($parent = 0, $level = 0, $tree, $showAlways = FALSE)
{
global $parents;
foreach ($tree as $row)
{
if ($parent == $row['parent'])
{
echo '";
if (in_array($row['id'], $parents) || $showAlways)
tree($row['id'], $level + 1, $tree, $showAlways);
}
}
}
?>